package com.zygh.questionnairesurvey.controller;

import com.zygh.questionnairesurvey.common.CommonResult;
import com.zygh.questionnairesurvey.entity.ProblemDetails;
import com.zygh.questionnairesurvey.server.ProblemDetailsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: questionnaire-survey
 * @description: 个人问题描述
 * @author: ID-Tang
 * @create: 2021-05-11 13:49
 **/
@RestController
@RequestMapping(value = "/problem-details")
@Api(tags = "个人问题描述")
public class ProblemDetailsController {
    @Resource
    ProblemDetailsService problemDetailsService;

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "批量操作个人问题描述")
    public Object insertAndUpdate(@RequestBody List<ProblemDetails> list) {
        Integer insert = problemDetailsService.insertAndUpdate(list);
        if (insert < 0) {
            return new CommonResult().validateFailed("操作失败,请稍后重试!");
        }
        return new CommonResult().success("操作成功!");
    }

    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除个人问题描述")
    public Object delete(@RequestBody List<Integer> ids) {
        Integer delete = problemDetailsService.delete(ids);
        if (delete < 1) {
            return new CommonResult().validateFailed("删除失败,请稍后重试!");
        }

        return new CommonResult().success("删除成功!");
    }

    @GetMapping("findDetailById")
    @ApiOperation(value = "根据警号和编号查询个人问题详情列表")
    public CommonResult findDetailById(String warningsignal, String problemId){
        return problemDetailsService.findDetailById(warningsignal,problemId);
    }

    @GetMapping("findDetailByDeptId")
    @ApiOperation(value = "根据部门查询该部门下个人问题详情个数")
    public CommonResult findDetailByDeptId(){
        return problemDetailsService.findDetailByDeptId();
    }


}
